package com.googlecode.bipol.war.google.apis.chart;

import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.List;
import javax.naming.NamingException;

import com.googlecode.bip.dao.deprecated.UserValueDB;
import com.googlecode.bip.entity.deprecated.UserValue;
//import com.googlecode.bipol.war.session.BiPolSession;

/**
 *
 * @author Claude CHOISNET
 */
@Deprecated // TODO: REMOVE
public class LineCharBuilder extends LineChar
{
    private final UserValueDB   userValueDB;
    private final Timestamp     dateFrom;
    private final Timestamp     dateTo;
    private final int           iduser;

    /**
     *
     * @param uSession
     * @param dateFrom
     * @param dateTo
     * @throws NamingException
     */
    public LineCharBuilder(
            //final BiPolSession  uSession,
            final Timestamp     dateFrom,
            final Timestamp     dateTo
            )
    {
        super( /*uSession*/ );

        this.userValueDB = new UserValueDB();
        this.dateFrom   = dateFrom;
        this.dateTo     = dateTo;
        this.iduser     = 0;//uSession.getUserid();
    }

    public void addAll() throws SQLException, NamingException
    {
        final List<Integer> idcategoryList = userValueDB.getCategoriesList( iduser, dateFrom, dateTo );

        for( int idcategory : idcategoryList ) {
            add( idcategory );
        }
    }

    /**
     *
     * @param idcategory
     * @throws java.sql.SQLException
     * @throws NamingException
     * @throws IllegalArgumentException
     */
    public void add( final int idcategory )
        throws java.sql.SQLException, IllegalArgumentException, NamingException
    {
        final List<UserValue> uvL = userValueDB.getUserValueList( idcategory, iduser, dateFrom, dateTo );

        super.add( idcategory, uvL );
    }

    /**
     *
     * @param idscategory
     * @throws IllegalArgumentException
     * @throws SQLException
     * @throws NamingException
     */
    public void add( final int...idscategory )
        throws  IllegalArgumentException,
                SQLException,
                NamingException
    {
        for(int id:idscategory) {
            add( id );
            }
    }
}
